package com.shuwen.gcdj.service.demo.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuwen.gcdj.common.api.CommonPage;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.bean.demo.request.Demo1QueryParam;
import com.shuwen.gcdj.bean.demo.response.Demo1QueryVO;
import com.shuwen.gcdj.entity.Demo1;
import com.shuwen.gcdj.mapper.mysql.Demo1Mapper;
import com.shuwen.gcdj.service.demo.Demo1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @oauth ldongxu
 *
 * @createDate 2021/11/17
 * @info
 */
@Service
public class Demo1ServiceImpl extends ServiceImpl<Demo1Mapper, Demo1> implements Demo1Service {

    @Autowired
    private Demo1Mapper demo1Mapper;

    @Override
    public CommonResult<CommonPage<Demo1QueryVO>> getList(Demo1QueryParam queryParam, Page<Demo1> page) {

        IPage<Demo1> pages = demo1Mapper.selectPage(page, null);

        IPage<Demo1QueryVO> convert = pages.convert(demo1 -> {
            Demo1QueryVO demo1QueryVO = new Demo1QueryVO();
            demo1QueryVO.setId(demo1.getId());
            demo1QueryVO.setName(demo1.getName());
            return demo1QueryVO;
        });

        return CommonResult.success(CommonPage.restPage(convert));
    }
}
